<?php
/**
 * Created by PhpStorm.
 * User: Woo
 * Date: 2018/3/22
 * Time: 17:17
 */

namespace App\Services;


use App\Models\Bookmark;
use Illuminate\Support\Facades\DB;

class NovelService
{
    public $readHistory;
    public function __construct(Bookmark $readHistory)
    {
        $this->readHistory = $readHistory;
    }

    /**
     * 用户的书签，每本书出现一次
     * @param $user_id
     */
    public function getBookMark($user_id){
        $t = $this->readHistory->getTable();
        $res = Bookmark::where($t.'.user_id', $user_id)
            ->join('t_novel as n','n.id',$t.'.novel_id')
            ->join('t_chapter as c','c.id',$t.'.chapter_id')
            ->orderByDesc($t.'.id')
            ->get([$t.'.novel_id',$t.'.chapter_id','n.title','n.author','n.cover','c.chapter_name']);
        return $res;
    }
}